package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;
    //channel/1
    @GetMapping("channel/{category1Id}")
    public Result<List<Map<String, Object>>> channel(@PathVariable Long category1Id) throws IOException {
        List<Map<String,Object>> maps= this.searchService.channel(category1Id);
        return Result.ok(maps);
    }
    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery query){
        AlbumSearchResponseVo responseVo = this.searchService.search(query);
        return Result.ok(responseVo);
    }
     @GetMapping("completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword){
        List<String> suggests = this.searchService.completeSuggest(keyword);
        return Result.ok(suggests);
    }
     @GetMapping("findRankingList/{category1Id}/{type}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long category1Id, @PathVariable String type){
        List<AlbumInfoIndexVo> albumInfoIndexVos = this.searchService.findRankingList(category1Id, type);
        return Result.ok(albumInfoIndexVos);
    }
}

